﻿using Apps.Common;
using Apps.Models;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;

namespace ReportViewerForMvc
{
    /// <summary>
    /// The Web Form used for rendering a ReportViewer control.
    /// </summary>
    public partial class SurfficeReportWebForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ReportViewer1.Drillthrough += new DrillthroughEventHandler(ReportViewer1_Drillthrough);
            BuildReportViewer();
        }

        private void BuildReportViewer()
        {
            if (!IsPostBack)
            {
                ReportViewerForMvc.ReportViewer.ID = ReportViewer1.ID;

                ReportViewer1.SetProperties(ReportViewerForMvc.ReportViewer);
            }
        }

        protected void ReportViewer1_Drillthrough(object sender, DrillthroughEventArgs e)
        {
            LocalReport localReport = (LocalReport)e.Report;
            IList<ReportParameter> list = localReport.OriginalParametersToDrillthrough;
            string TEST_CODE = list.Where(m => m.Name == "TEST_CODE").FirstOrDefault().Values[0].ToString();

            var Data = Apps.BLL.Report.ReportBLL<V_STATS_RC_PLAN_RESULT>.GetReportDataList(m => m.TEST_CODE == TEST_CODE);

            localReport.DataSources.Add(new ReportDataSource { Value = Data, Name = "DataSet1" });

        }
        
    }
}